package com.gsp.gspframeworktest.controller;

import com.gsp.gspframework.annotation.Action;
import com.gsp.gspframework.annotation.Controller;
import com.gsp.gspframework.annotation.Inject;
import com.gsp.gspframework.bean.Data;
import com.gsp.gspframework.bean.FileParam;
import com.gsp.gspframework.bean.Param;
import com.gsp.gspframework.bean.View;
import com.gsp.gspframeworktest.entity.Customer;
import com.gsp.gspframeworktest.service.impl.CustomerServiceImpl;

import java.util.List;
import java.util.Map;

@Controller
public class CustomerController {

    @Inject
    CustomerServiceImpl customerService;

    @Action("get:/customer")
    public View index(Param param) {
        List<Customer> customerList = customerService.getCustomerList();
        return new View("customer/customer.jsp").addModel("customers", customerList);
    }

    @Action("get:/customer_create")
    public View goCreateCustomer(Param param) {
        return new View("customer/customer_create.jsp");
    }

    @Action("post:/customer_create")
    public Data createCustomer(Param param) {
        Map<String, Object> fieldMap = param.getFieldMap();
        FileParam fileParam = param.getFile("photo");
        boolean result = customerService.createCustomer(fieldMap, fileParam);
        return new Data(result);
    }


}
